<template>
	<div class='container-padding' v-if="orderDetail != null">
		<nav-header></nav-header>
		<custom-order @useWalletPay="useWalletPay"></custom-order>
		<footor-buy-bar :isUseWallet="isUseWallet" v-if="orderDetail.order_state < 20">
		</footor-buy-bar>
	</div>
</template>

<script>
	import { mapGetters, mapState, mapActions, mapMutations } from 'vuex';
	import header from "@/components/header/header"
	import footorBuyBar from "@/pages/order-detail/components/footor-buy-bar"
	import customOrder from "@/pages/order-detail/activity-to-pay/custom-order/custom-order"
	import server from '@/server/api';
	
	export default {
		data() {
			return {
				isUseWallet: false,
				payMethod:'weixin'
			}
		},
		computed: {
			...mapState(['orderDetail']),
			...mapGetters(['formatDate']),
		},
		components: {
			"custom-order":customOrder,
			"nav-header": header,
			"footorBuyBar": footorBuyBar
		},
		mounted() {
		},
		created() {
			const _this = this;
			let order_label = this.$route.params.order_label;
			let param = {
				order_label: order_label,
				member_id: 101076
			}
			if(this.$route.params.all_no.substring(0, this.$route.params.all_no.indexOf("=")) == "order_id") {
				param.order_id = this.$route.params.all_no.substring(this.$route.params.all_no.indexOf("=") + 1, this.$route.params.all_no.length);

			} else {
				param.all_no = this.$route.params.all_no.substring(this.$route.params.all_no.indexOf("=") + 1, this.$route.params.all_no.length);
			}
			server.post("/index/order/order_info", param, function(res) {
				var item_num = 0;
				for(var i = 0; i < res.data.goods_list.length; i++) {
					if(res.data.order_label == 4) {
						res.data.tpl_name = "custom_order";
						res.data.attend_time = _this.formatDate(new Date(res.data.customized_time * 1000), 'yyyy年mm月dd日 hh:ii');

					} else {
						res.data.tpl_name = "activity_order";
						res.data.goods_list[i].attend_time = _this.formatDate(new Date(res.data.goods_list[i].activity.ua_start_time * 1000), 'yyyy-mm-dd');
					}
					item_num += res.data.goods_list[i].item_num;
				}
				if(res.data.order_label == 4) {
					var payedMoney = 0;
					// 计算已经支付金额
					for(var i = 0; i < res.data.pay_log.length; i++) {
						payedMoney += (res.data.pay_log[i].pay_money * 100)
					}
					payedMoney = payedMoney / 100;
					res.data.payedMoney = payedMoney;
					// 获取待支付金额
					if(res.data.project == '预付款') {
						res.data.topayMoney = res.data.deposit
					} else {
						res.data.topayMoney = res.data.order_amount - payedMoney
					}
				} else {
					res.data.topayMoney = res.data.order_amount
				}
				res.data.item_num = item_num;
				res.data.unit_price = res.data.order_amount / item_num;
				res.data.total_price = res.data.order_amount;
				_this.$store.state.orderDetail = res.data;
			})
		},
		methods: {
			...mapActions(['getOrderDetail', "getOrderDetailOther"]),
			choosePayMethod(payType){
				if(this.payMethod != payType){
					this.payMethod = payType
				}
			},
			useWalletPay(val){

				this.isUseWallet = val;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container-padding {
		width: 100%;
		margin: 90px 0 0;
		
	}
</style>